#include <cuda_runtime.h>

extern "C" __global__ void vector_add(
    const float* a,
    const float* b,
    float* result,
    size_t n
) {
    size_t idx = blockIdx.x * blockDim.x + threadIdx.x;
    if (idx < n) {
        result[idx] = a[idx] + b[idx];
    }
}

// 封装函数，接受stream参数
extern "C" void launch_vector_add(
    const float* a,
    const float* b,
    float* result,
    size_t n,
    cudaStream_t stream
) {
    size_t block_size = 256;
    size_t grid_size = (n + block_size - 1) / block_size;
    vector_add<<<grid_size, block_size, 0, stream>>>(a, b, result, n);
}